import config from '@/config'
import { Env, Platform } from '@/interface'
// #ifdef MP-WEIXIN
import wxSdk from 'umtrack-wx'
// #endif

// #ifdef MP-ALIPAY
import aliSdk from 'umtrack-alipay'
// #endif

import { App } from 'vue'
import { usePlatform } from '../hooks/usePlatform'

function getUmaSdk() {
  // #ifdef MP-WEIXIN
  return wxSdk
  // #endif
  // #ifdef MP-ALIPAY
  return aliSdk
  // #endif
}

const sdk = getUmaSdk()

const uma_config = {
  appKey: '5f5740c1b4739632429ad7a3',
  useOpenid: true,
  autoGetOpenid: true,
  debug: config.env !== 'release',
  // 新版本api有当前属性 types问题ts会抛错
  // enableVerify: true,
  uploadUserInfo: true,
}

class UMA {
  init() {
    // if (config.env !== Env.release) return
    return
    if (usePlatform() === Platform.alipay) {
      uma_config.appKey = '5f5740ffb4739632429ad7c0'
    }


    sdk.init(uma_config)
  }

  trackEvent(key: string, options: any) {
    sdk.trackEvent(key, options)
  }

  install(app: App<Element>) {
    app.provide('uma', sdk)
  }
}

const uma = new UMA()
uma.init()
export default uma
